﻿/**
 * @usage	全屏、音乐控制、弹出窗口、关闭窗口等常见Top栏初始化类
 * 
 */
package org.nickro.project.objectInit
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.display.SimpleButton;
	import flash.events.Event;
	
	import org.nickro.project.events.LoadEvent;
	import org.nickro.project.web.BrowserUtil;
	import org.nickro.project.load.SoundManager;
	import org.nickro.project.objectInit.ButtonInitialize;
	import org.nickro.project.debug.Console;
	/**
	 * ...
	 * @author com.nickro
	 */
	public class TopBase extends MovieClip
	{
		private var _isSoundOnOff:Boolean = true;
		private var mama:Sprite;
		public function TopBase(mainInstance:Sprite) 
		{
			mama = mainInstance;
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void
		{
			initInteractive();
		}
		
		private function initInteractive():void
		{
			ButtonInitialize.btnClick(emailBtn, onEmail);
			ButtonInitialize.btnClick(contactBtn, onContact);
			ButtonInitialize.btnClick(closeBtn, onClose);
			ButtonInitialize.btnClick(audioBtn, onAudio);
			ButtonInitialize.btnClick(sndBtn, onSnd);
			ButtonInitialize.btnEffect(sndBtn, sndBtn, 1, 30);
			sndBtn.xShape.visible = !_isSoundOnOff;
			
			SoundManager.getInstance().addExternalSound("sound/[the crystal method]Born Too Slow-The Crystal Method.mp3","sound");
			SoundManager.getInstance().addEventListener(LoadEvent.COMPLETE, onSoundLoaded);
		}
		
		private function onSoundLoaded(e:LoadEvent):void
		{
			SoundManager.getInstance().playSound("sound");
		}

		private function onEmail():void
		{
			BrowserUtil.sendEmail("com.nickroliu@gmail.com", "hello ExternalInterface", "hello Email");
		}

		private function onContact():void
		{
			BrowserUtil.openNewWindow("img/contact.html");
		}

		private function onClose():void
		{
			BrowserUtil.closeWindow();
		}

		private function onSnd():void
		{
			_isSoundOnOff = !_isSoundOnOff;
			sndBtn.xShape.visible = !_isSoundOnOff;
			_isSoundOnOff?SoundManager.getInstance().playSound("sound"):SoundManager.getInstance().pauseSound("sound");
		}
		
		private function onAudio():void
		{
			audioBtn.selected = _isSoundOnOff;
			if (audioBtn.selected) audioBtn.gotoAndStop(20);
			else audioBtn.gotoAndPlay(2);
			_isSoundOnOff = !_isSoundOnOff;
			_isSoundOnOff?SoundManager.getInstance().playSound("sound"):SoundManager.getInstance().pauseSound("sound");
		}
	}
}